package dobest.ray.com.jiongjiong.activity.login;

import android.content.Context;

import com.android.volley.VolleyError;
import com.dobest.ray.corelibs.logic.BaseLogic;

import dobest.ray.com.jiongjiong.activity.Presenter;
import dobest.ray.com.jiongjiong.authority.AuthorityContext;
import dobest.ray.com.jiongjiong.authority.LoggedIn;
import dobest.ray.com.jiongjiong.bean.BaseData;
import dobest.ray.com.jiongjiong.callback.PresenterCallBack;
import dobest.ray.com.jiongjiong.constants.Constant;
import dobest.ray.com.jiongjiong.logicCache.cacheBaseLogic.LoginManager;

/**
 * Created by Administrator on 2016/3/10.
 */
public class LoginPresenter extends Presenter {
    private LoginManager manager;

    public LoginPresenter(PresenterCallBack callBack) {
        this.callback = callBack;
        manager = new LoginManager();
    }

    /**
     * 登陆
     *
     * @param c
     * @param phone
     * @param password
     */
    public void doLogin(Context c, String phone, String password) {
        manager.doLogin(c, phone, password, new BaseLogic.NListener<BaseData>() {
            @Override
            public void onResponse(BaseData data) {
                if (data.errorCode == Constant.STATUS_CODE_200) {
                    AuthorityContext.getContext().setAuthority(new LoggedIn());
                }

            }

            @Override
            public void onErrResponse(VolleyError error) {

            }
        });
    }

    /**
     * 获取验证码
     *
     * @param c
     * @param uid
     */
    public void getVCode(Context c, String uid) {
        manager.getVCode(c, uid, new BaseLogic.NListener<BaseData>() {
            @Override
            public void onResponse(BaseData data) {
                if (data.errorCode == Constant.STATUS_CODE_200) {

                }
            }

            @Override
            public void onErrResponse(VolleyError error) {

            }
        });

    }

    /**
     * 注册操作
     */
    public void doRegister(Context c, String phone, String password, String code) {
        manager.doRegister(c, phone, password, code, new BaseLogic.NListener<BaseData>() {
            @Override
            public void onResponse(BaseData data) {

            }

            @Override
            public void onErrResponse(VolleyError error) {

            }
        });

    }

}
